﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SiGeSIB.GUI.Properties;

namespace SiGeSIB.GUI.Common
{
	public partial class DefaultStatusBar : UserControl
	{
		public enum EStatusImage
		{
			Info,
			Error
		}

		public enum EStatusForeColor
		{
			Default,
			Red
		}

		private Image ErrorImage = Resources.stop_alt;
		private Image InfoImage = Resources.info;
		private string _Message;

		public DefaultStatusBar()
		{
			InitializeComponent();
			_Message = statusStrip1.Text;
		}

		public string Message
		{
			get { return _Message; }
			set 
			{
				_Message = value;

				string lblMessage = _Message;

				using (Graphics g = CreateGraphics())
				{
					int maxSize = this.Width - 30;

					if (g.MeasureString(_Message, lblStatusMessage.Font).Width > maxSize)
					{
						lblMessage = _Message.FitSize(maxSize, lblStatusMessage.Font, "...");
						lblStatusMessage.ToolTipText = _Message;
					}

				}

				lblStatusMessage.Text = lblMessage;
			}
		}

		public void SetIcon(EStatusImage status)
		{
			switch (status)
			{
				case EStatusImage.Info:
					lblStatusMessage.Image = InfoImage;
					break;
				case EStatusImage.Error:
					lblStatusMessage.Image = ErrorImage;
					break;
				default:
					break;
			}
		}
		public void SetForeground(Color color)
		{
			lblStatusMessage.ForeColor = color;
		}
	}
}
